package com.api.shopapi.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.shopapi.entity.NurseStaffRel;
import com.api.shopapi.entity.dto.NurseStaffRelDTO;
import com.api.shopapi.mapper.NurseStaffRelMapper;
import com.api.shopapi.service.NurseStaffRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service("NurseStaffRelServiceImplOne")
public class NurseStaffRelServiceImpl implements NurseStaffRelService {

    @Autowired
    private NurseStaffRelMapper nurseStaffRelMapper;


    @Override
    public int insert(JSONObject jsonObject) {
        String nurseCode = jsonObject.getString("nurseCode");
        JSONArray nurseStaffCodeArr = jsonObject.getJSONArray("nurseStaffCodeArr");
        NurseStaffRel nurseStaffRel = new NurseStaffRel();
        int count = 0;
        for (Object i : nurseStaffCodeArr){
            nurseStaffRel.setNurseStaffRelCode(UUID.randomUUID().toString());
            nurseStaffRel.setNurseCode(nurseCode);
            nurseStaffRel.setStaffCode((String) i);
            nurseStaffRelMapper.insert(nurseStaffRel);
            count++;
        }
        return count;
    }

    @Override
    public
    int insert2(NurseStaffRel nurseStaffRel){
        return nurseStaffRelMapper.insert(nurseStaffRel);
    }

    @Override
    public NurseStaffRel getByNurseCodeAndNurseStaffCode(String nurseCode, String nurseStaffCode) {
        return nurseStaffRelMapper.getByNurseCodeAndNurseStaffCode(nurseCode,nurseStaffCode);
    }

    @Override
    public List<NurseStaffRelDTO> getListByNurseCode(String nurseCode) {
        return nurseStaffRelMapper.getListByNurseCode(nurseCode);
    }

    @Override
    public NurseStaffRel getByStaffCode(String staffCode) {
        return nurseStaffRelMapper.getByNurseStaffCode(staffCode);
    }

    @Override
    public int delByNurseCodeAndNurseStaffCode(String nurseCode, String nurseStaffCode) {
        return nurseStaffRelMapper.delByNurseCodeAndNurseStaffCode(nurseCode,nurseStaffCode);
    }

    @Override
    public
    int delete(String nurseStaffRelCode){
        return nurseStaffRelMapper.delete(nurseStaffRelCode);
    }

}
